home *** CD-ROM | disk | FTP | other *** search
- ; RWSUB - disk read/write subroutine for compiled BASIC
- ; Copyright 1983 Data Base Decisions
- ; CALL RWSUB(FIL$,FCB$,FUNC%,SBYTELO%,SBYTEHI%,NOBYTES%,DTASEG%,RETCODE%)
- ; FIL$ is the name of the file to be read or written
- ; FCB$ is a work area - allocate 40 spaces
- ; FUNC% indicates reading (0), writing (1), or creating & writing (2)
- ; SBYTELO% is the low part of the start byte
- ; SBYTEHI% is the high part of the start byte (HI*65536+LO)
- ; NOBYTES% is the number of bytes to be read/written
- ; DTASEG% is the segment to be read into or written from
- ; RETCODE% is an error return code
-
- skip equ 2 ; 2 for compiled, 1 for interpretive
-
- cseg segment para public 'code'
- public rwsub
- rwsub proc far
- assume cs:cseg,ds:nothing,ss:nothing,es:nothing
-
- push bp
- mov bp,sp
-
- push ds ; save orig ds
- mov si,[bp+8] ; point to DTASEG%
- mov ax,[si]
- mov ds,ax ; now in ds
- xor dx,dx ; clear dx
- mov ah,1ah
- int 21h ; set dta
- pop ds ; back to orig ds
-
- ; parse FIL$ into FCB$
- mov si,[bp+20] ; point to FIL$
- add si,skip
- mov si,[si]
- mov di,[bp+18] ; point to FCB$
- add di,skip
- mov di,[di]
- mov ax,2901h
- int 21h ; parse file name
- cmp al,0 ; error?
- jz p005 ; no
- mov ah,0 ; set parse error
- jmp p030
-
- p005: ; open the file
- mov si,[bp+18] ; point to FCB$
- add si,skip
- mov dx,[si] ; fcb address
- mov si,[bp+16] ; point to FUNC%
- mov al,[si] ; get access code in al
- mov ah,16h
- cmp al,2 ; create?
- jz p010 ; yes
- mov ah,0fh ; normal open
- mov cx,0 ; clear attributes
- p010: int 21h ; open the file
- cmp al,0 ; error?
- jz p015 ; no
- mov ah,1 ; set open error
- jmp p030
-
- p015: ; fix up the fcb
- mov si,[bp+18] ; point to FCB$
- add si,skip
- mov si,[si]
- mov bx,14
- add bx,si ; point to record size
- mov ax,1
- mov [bx],ax ; set record size
- mov bx,32
- add bx,si ; point to current record
- mov [bx],ah ; zero it
- inc bx
- mov si,[bp+14] ; point to SBYTELO%
- mov ax,[si] ; get the number
- mov [bx],ax ; and save in the fcb
- inc bx
- inc bx
- mov si,[bp+12] ; point to SBYTEHI%
- mov ax,[si] ; get the number
- mov [bx],ax ; and save in the fcb
-
- ; read/write the file
- mov si,[bp+18] ; point to FCB$
- add si,skip
- mov dx,[si] ; fcb address
- mov si,[bp+10] ; point to NOBYTES%
- mov cx,[si] ; number of bytes to read/write
- mov si,[bp+16] ; point to FUNC%
- mov ah,[si] ; 0 for read, 1 for write, 2 for create
- cmp ah,2 ; create?
- jnz p020 ; no
- dec ah ; yes - make it a write
- p020: add ah,27h ; setup interrupt function
- int 21h ; read/write the file
- mov si,[bp+10] ; point to NOBYTES%
- mov [si],cx ; save bytes read/written
- push ax ; save errors, if any
-
- ; close the file
- mov ah,10h
- int 21h ; close the file
- cmp al,0 ; any errors?
- jz p025 ; no
- pop bx ; restore ax into bx
- mov ah,3 ; indicate close error
- jmp p030
-
- p025: pop ax
- cmp al,0 ; any read/write errors?
- jz p040 ; no
- mov ah,2 ; indicate error type
-
- p030: ; error handler
- mov si,[bp+6] ; point to RETCODE%
- mov [si],ax ; save the error
-
- p040: ; return to caller
- pop bp
- ret 16
-
- rwsub endp
- cseg ends
- end
-